package com.ape.mapsa.produccion.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;
import org.springframework.stereotype.Repository;

import com.ape.mapsa.produccion.model.ProdOperator;

@Repository
public class OperatorDAOImpl extends GenericDAOImpl<ProdOperator, Long> implements OperatorDAO {
	private static final Logger log = Logger.getLogger(OperatorDAOImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<ProdOperator> getOperators(String query) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ProdOperator.class);
		SimpleExpression firstNameRest = Restrictions.like("firstname", query, MatchMode.START).ignoreCase();
		SimpleExpression lastNameRest = Restrictions.like("lastname", query, MatchMode.START).ignoreCase();
		criteria.add(Restrictions.or(firstNameRest, lastNameRest));
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ProdOperator> getAllOperators() {
		return sessionFactory.getCurrentSession().createCriteria(ProdOperator.class).add(Restrictions.eq("state", 1)).list();
	}
}
